#!/usr/bin/php
<?php
/*
 * Git pre-commit hook
 *   To use this just symlink it to .git/hooks/pre-commit or copy it there and make modifications as needed.
 */
$baseDir = sprintf('%s/src/tests', dirname(dirname(dirname(__FILE__))));
chdir($baseDir);
printf("%sGit pre-commit hook %1\$s", PHP_EOL);
$projectName = basename(getcwd());
exec('phpunit --configuration phpunit.xml ./', $output, $returnCode); // Assuming cwd here
if ($returnCode !== 0) {
    $minimalTestSummary = array_pop($output);
    printf("Test suite for %s failed: ", $projectName);
    echo implode("\n", $output);
    printf("( %s ) %s%2\$s", $minimalTestSummary, PHP_EOL);
    exit(1);
}
printf("All tests for %s passed.%s%2\$s", $projectName, PHP_EOL);
exit(0);
